﻿
using CSharpLibs.Annotations;

namespace System.IO
{
	[Builtin]
	public static class Directory
	{
		public static DirectoryInfo CreateDirectory(string s)
		{
 			DirectoryCreateRaw(s);
			return new DirectoryInfo(s);
		}

		[BuiltinMethod, BuiltinSemantics("directory_create")]
		[UsedModStatics("System.ExternalState.fsstate")]
		private static void DirectoryCreateRaw(string s)
		{ return; }

		public static void Delete(string s)
		{ Delete(s, false); }

		[BuiltinMethod, BuiltinSemantics("directory_delete")]
		[UsedModStatics("System.ExternalState.fsstate")]
		public static void Delete(string s, bool b)
		{ ;}

		public static Collections.Generic.IEnumerable<string> EnumerateDirectories(string s)
		{
			char[] wc = new char[1];
			wc[0] = '*';
			String ss = new String(wc);

			return EnumerateDirectories(s, ss, SearchOption.TopDirectoryOnly); 
		}

		public static Collections.Generic.IEnumerable<string> EnumerateDirectories(string s, string match)
		{ return EnumerateDirectories(s, match, SearchOption.TopDirectoryOnly); }

		public static Collections.Generic.IEnumerable<string> EnumerateDirectories(string s, string match, SearchOption opt)
		{
			Collections.Generic.List<string> dl = new Collections.Generic.List<string>();

			string[] ff = SubDirOrFileArray(s, match, opt, 2);
			for(int i = 0; i < ff.Length; ++i)
				dl.Add(ff[i]);

			return dl;
		}

		public static Collections.Generic.IEnumerable<string> EnumerateFiles(string s)
		{
			char[] wc = new char[1];
			wc[0] = '*';
			String ss = new String(wc);

			return EnumerateFiles(s, ss, SearchOption.TopDirectoryOnly);
		}

		public static Collections.Generic.IEnumerable<String> EnumerateFiles(string s, string match)
		{ return EnumerateFiles(s, match, SearchOption.TopDirectoryOnly); }

		public static Collections.Generic.IEnumerable<string> EnumerateFiles(string s, string match, SearchOption opt)
		{
			Collections.Generic.List<string> fl = new Collections.Generic.List<string>();
			
			string[] ff = SubDirOrFileArray(s, match, opt, 1);
			for(int i = 0; i < ff.Length; ++i)
				fl.Add(ff[i]);

			return fl;
		}

		[BuiltinMethod, BuiltinSemantics("directory_getfilesordirs")]
		[UsedModStatics("System.ExternalState.fsstate")]
		private static string[] SubDirOrFileArray(string s, string match, SearchOption opt, int filesordirs /*1 for files 2 for dirs*/)
		{ return null; }

		[BuiltinMethod, BuiltinSemantics("directory_exists")]
		[UsedModStatics("System.ExternalState.fsstate")]
		public static bool Exists(string s)
		{ return false; }

		[BuiltinMethod, BuiltinSemantics("directory_current")]
		[UsedModStatics("System.ExternalState.fsstate")]
		public static string GetCurrentDirectory()
		{ return null; }

		public static string[] GetDirectories(string s)
		{ return new Collections.Generic.List<string>(EnumerateDirectories(s)).ToArray(); }

		public static string[] GetDirectories(string s, String match)
		{ return new Collections.Generic.List<string>(EnumerateDirectories(s, match)).ToArray(); }

		public static string[] GetDirectories(string s, String match, SearchOption opt)
		{ return new Collections.Generic.List<string>(EnumerateDirectories(s, match, opt)).ToArray(); }

		public static string[] GetFiles(string s)
		{ return new Collections.Generic.List<string>(EnumerateFiles(s)).ToArray(); }

		public static string[] GetFiles(string s, string match)
		{ return new Collections.Generic.List<string>(EnumerateFiles(s, match)).ToArray(); }

		public static string[] GetFiles(string s, string match, SearchOption opt)
		{ return new Collections.Generic.List<string>(EnumerateFiles(s, match, opt)).ToArray(); }

		[BuiltinMethod, BuiltinSemantics("directory_move")]
		[UsedModStatics("System.ExternalState.fsstate")]
		public static void Move(string sourceDirName, string destDirName)
		{ ;}
	}
}
